﻿package mortal.game.view.task.guild
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.systemSetting.*;
    import mortal.game.view.task.data.*;

    public class GuildTaskShareListRender extends NoSkinCellRenderer
    {
        private var _txtName:GTextFiled;
        private var _btnIWantGet:GLoadingButton;
        private var _txtTimes:GTextFiled;
        private var _share:GuildTaskShareListData;
        private var _bg:ScaleBitmap;

        public function GuildTaskShareListRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            this._txtName = UIFactory.gTextField("", 12, 4, 180, 20, this, _loc_1);
            this._txtTimes = UIFactory.gTextField("", 44, 23, 180, 20, this, _loc_1);
            this._txtTimes.textColor = 65280;
            this._txtTimes.text = "";
            this._btnIWantGet = UIFactory.gLoadingButton(ImagesConst.GuildTaskIWantGetBtn_upSkin, 185, 14, 67, 23, this);
            this._btnIWantGet.configEventListener(MouseEvent.CLICK, this.linkHandler);
            return;
        }// end function

        private function linkHandler(event:MouseEvent) : void
        {
            var _loc_4:Array = null;
            var _loc_5:TaskInfo = null;
            var _loc_2:* = Cache.instance.task.getTaskByGroupInTaskDoing(ETaskGroup._ETaskGroupGuild);
            if (_loc_2 == null || _loc_2.length == 0)
            {
                _loc_4 = Cache.instance.task.getTaskByGroupInTaskCanget(ETaskGroup._ETaskGroupGuild);
                if (_loc_4.length > 0)
                {
                    _loc_5 = _loc_4[0] as TaskInfo;
                    if (Cache.instance.npc.selectedNpc != null)
                    {
                        GameProxy.task.getTask(Cache.instance.npc.selectedNpc.npcInfo.tnpc.code, _loc_5.stask.code);
                    }
                    else
                    {
                        TaskUtil.linkTask(_loc_5);
                        GameController.taskImpl.guildTaskGetWin.hide();
                        return;
                    }
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(21178));
                    return;
                }
            }
            var _loc_3:* = _loc_2[0];
            if (_loc_3 != null && _loc_3.isComplete())
            {
                MsgManager.showRollTipsMsg(Language.getString(21179));
                return;
            }
            if (_loc_3 != null && _loc_3.playerTask.canShare)
            {
                MsgManager.showRollTipsMsg(Language.getString(21180));
                return;
            }
            GameProxy.task.getSharedGuildTask(this._share.shareData.entityId, this._share.shareData.id);
            GameProxy.task.guildTaskGetShareList();
            EffectManager.glowFilterUnReg(this._btnIWantGet);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._share = param1 as GuildTaskShareListData;
            if (this._bg != null)
            {
                this._bg.dispose();
                this._bg = null;
            }
            if (this._share.needBg)
            {
                this._bg = UIFactory.bg(0, 0, 264, 51, null, ImagesConst.GuildTaskRenderBg0);
            }
            else
            {
                this._bg = UIFactory.bg(0, 0, 264, 51, null, ImagesConst.GuildTaskRenderBg1);
            }
            this.addChildAt(this._bg, 0);
            this._txtName.htmlText = this._share.shareData.time.hours + ":" + this._share.shareData.time.minutes + "  " + this._share.shareData.playerName + "[" + GameDefConfig.instance.getItem("EGuildPostion", this._share.shareData.position).text + "]";
            this._txtTimes.htmlText = Language.getStringByParam(21181, this._share.shareData.getCount);
            if (this._share.shareData.isGet)
            {
                this._btnIWantGet.mouseEnabled = false;
                this._btnIWantGet.filters = [FilterConst.colorFilter];
            }
            else if (this._share.shareData.getCount >= 5)
            {
                this._btnIWantGet.mouseEnabled = false;
                this._btnIWantGet.filters = [FilterConst.colorFilter];
            }
            else
            {
                this._btnIWantGet.mouseEnabled = true;
                this._btnIWantGet.filters = [];
                if (!ClientSetting.local.getIsDone(IsDoneType.hasGuideGuildTaskOrange))
                {
                    ClientSetting.local.setIsDone(true, IsDoneType.hasGuideGuildTaskOrange);
                    ClientSetting.save(true);
                    EffectManager.glowFilterReg(this._btnIWantGet);
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            EffectManager.glowFilterUnReg(this._btnIWantGet);
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtTimes.dispose(param1);
            this._txtTimes = null;
            this._btnIWantGet.dispose(param1);
            this._btnIWantGet = null;
            if (this._bg != null)
            {
                this._bg.dispose();
                this._bg = null;
            }
            return;
        }// end function

    }
}
